clipboard: Reimplement Wayland clipboard using vfuncs
authorBenjamin Otte <otte@redhat.com>
Tue, 20 Aug 2013 13:35:58 +0000 (15:35 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 20 Aug 2013 14:34:29 +0000 (16:34 +0200)
This way, the Wayland and the regular clipboard implementation can both
be compiled in and selected based on the display in use.

One thing potentially broken now is text mime type handling as Wayland
seemed to use different mime types in some places.

gtk/Makefile.am
gtk/gtkclipboard-wayland.c
gtk/gtkclipboard-waylandprivate.h [new file with mode: 0644]
gtk/gtkclipboard.c

index 189143526785c2d4ca34f5298ff299e885bc368f..48d83758ce0097944f0fbe43a30ae14a518ddd5b 100644 (file)
@@ -427,6 +427,7 @@ gtk_private_h_sources =             \
        gtkcairoblurprivate.h   \
        gtkcellareaboxcontextprivate.h  \
        gtkclipboardprivate.h           \
+       gtkclipboard-waylandprivate.h   \
        gtkcolorswatchprivate.h \
        gtkcoloreditorprivate.h \
        gtkcolorplaneprivate.h  \
@@ -1018,18 +1019,11 @@ gtk_clipboard_dnd_c_sources =   \
        gtkclipboard-quartz.c   \
        gtkdnd-quartz.c
 else
-if USE_WAYLAND
-if !USE_X11
 # No wayland gtkdnd-wayland.c yet
 gtk_clipboard_dnd_c_sources =  \
+       gtkclipboard.c \
        gtkclipboard-wayland.c \
        gtkdnd.c
-else
-gtk_clipboard_dnd_c_sources = gtkclipboard.c gtkdnd.c
-endif
-else
-gtk_clipboard_dnd_c_sources = gtkclipboard.c gtkdnd.c
-endif
 endif
 
 # we use our own built_sources variable rules to avoid automake's
index 3ed3b4e6e4b8f4660dd368611dd4c55245bdbbc9..8ab173026c3b509d6b60236e1d84708affc34f8a 100644 (file)
  */
 
 #include "config.h"
+
+#include "gtkclipboard-waylandprivate.h"
+
 #include <string.h>
 
-#include "gtkclipboard.h"
-#include "gtkinvisible.h"
 #include "gtkmain.h"
 #include "gtkmarshalers.h"
 #include "gtkintl.h"
-#include "gtktextbuffer.h"
 #include "gtkselectionprivate.h"
 
-#include "../gdk/gdk.h"
-#include "../gdk/wayland/gdkwayland.h"
-
-enum {
-    OWNER_CHANGE,
-    LAST_SIGNAL
-};
-
-typedef struct _GtkClipboardClass GtkClipboardClass;
-
-typedef struct _SetContentClosure SetContentClosure;
-struct _GtkClipboard
-{
-  GObject parent_instance;
-
-  GObject *owner;
-  GdkDisplay *display;
-
-  GdkAtom selection;
-
-  SetContentClosure *last_closure;
-};
-
-struct _GtkClipboardClass
-{
-  GObjectClass parent_class;
-
-  void (*owner_change) (GtkClipboard        *clipboard,
-                        GdkEventOwnerChange *event);
-};
-
-static void gtk_clipboard_class_init   (GtkClipboardClass   *class);
-static void gtk_clipboard_finalize     (GObject             *object);
-static void gtk_clipboard_owner_change (GtkClipboard        *clipboard,
-                                        GdkEventOwnerChange *event);
-
-static GObjectClass *parent_class;
-static guint         clipboard_signals[LAST_SIGNAL] = { 0 };
-
-GType
-gtk_clipboard_get_type (void)
-{
-  static GType clipboard_type = 0;
-
-  if (!clipboard_type)
-    {
-      const GTypeInfo clipboard_info =
-        {
-          sizeof (GtkClipboardClass),
-          NULL,           /* base_init */
-          NULL,           /* base_finalize */
-          (GClassInitFunc) gtk_clipboard_class_init,
-          NULL,           /* class_finalize */
-          NULL,           /* class_data */
-          sizeof (GtkClipboard),
-          0,              /* n_preallocs */
-          (GInstanceInitFunc) NULL,
-        };
-
-      clipboard_type = g_type_register_static (G_TYPE_OBJECT, I_("GtkClipboard"),
-                                               &clipboard_info, 0);
-    }
-
-  return clipboard_type;
-}
+#ifdef GDK_WINDOWING_WAYLAND
+
+static void gtk_clipboard_wayland_owner_change     (GtkClipboard             *clipboard,
+                                                    GdkEventOwnerChange      *event);
+static gboolean gtk_clipboard_wayland_set_contents (GtkClipboard             *clipboard,
+                                                    const GtkTargetEntry     *targets,
+                                                    guint                     n_targets,
+                                                    GtkClipboardGetFunc       get_func,
+                                                    GtkClipboardClearFunc     clear_func,
+                                                    gpointer                  user_data,
+                                                    gboolean                  have_owner);
+static void gtk_clipboard_wayland_clear            (GtkClipboard             *clipboard);
+static void gtk_clipboard_wayland_request_contents (GtkClipboard             *clipboard,
+                                                    GdkAtom                   target,
+                                                    GtkClipboardReceivedFunc  callback,
+                                                    gpointer                  user_data);
+static void gtk_clipboard_wayland_set_can_store    (GtkClipboard             *clipboard,
+                                                    const GtkTargetEntry     *targets,
+                                                    gint                      n_targets);
+static void gtk_clipboard_wayland_store            (GtkClipboard             *clipboard);
+
+G_DEFINE_TYPE (GtkClipboardWayland, gtk_clipboard_wayland, GTK_TYPE_CLIPBOARD);
 
 static void
-gtk_clipboard_class_init (GtkClipboardClass *class)
+gtk_clipboard_wayland_class_init (GtkClipboardWaylandClass *klass)
 {
-  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
-
-  parent_class = g_type_class_peek_parent (class);
+  GtkClipboardClass *clipboard_class = GTK_CLIPBOARD_CLASS (klass);
 
-  gobject_class->finalize = gtk_clipboard_finalize;
-
-  class->owner_change = gtk_clipboard_owner_change;
-
-  clipboard_signals[OWNER_CHANGE] =
-    g_signal_new (I_("owner-change"),
-                  G_TYPE_FROM_CLASS (gobject_class),
-                  G_SIGNAL_RUN_FIRST,
-                  G_STRUCT_OFFSET (GtkClipboardClass, owner_change),
-                  NULL, NULL,
-                  _gtk_marshal_VOID__BOXED,
-                  G_TYPE_NONE, 1,
-                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
-}
-
-static void
-gtk_clipboard_finalize (GObject *object)
-{
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  clipboard_class->set_contents = gtk_clipboard_wayland_set_contents;
+  clipboard_class->clear = gtk_clipboard_wayland_clear;
+  clipboard_class->request_contents = gtk_clipboard_wayland_request_contents;
+  clipboard_class->set_can_store = gtk_clipboard_wayland_set_can_store;
+  clipboard_class->store = gtk_clipboard_wayland_store;
+  clipboard_class->owner_change = gtk_clipboard_wayland_owner_change;
 }
 
 static void
-clipboard_display_closed (GdkDisplay   *display,
-                         gboolean      is_error,
-                         GtkClipboard *clipboard)
+gtk_clipboard_wayland_init (GtkClipboardWayland *clipboard)
 {
-  GSList *clipboards;
-
-  clipboards = g_object_get_data (G_OBJECT (display), "gtk-clipboard-list");
-  g_object_run_dispose (G_OBJECT (clipboard));
-  clipboards = g_slist_remove (clipboards, clipboard);
-  g_object_set_data (G_OBJECT (display), I_("gtk-clipboard-list"), clipboards);
-  g_object_unref (clipboard);
 }
 
-static GtkClipboard *
-clipboard_peek (GdkDisplay *display, 
-               GdkAtom     selection,
-               gboolean    only_if_exists)
-{
-  GtkClipboard *clipboard = NULL;
-  GSList *clipboards;
-  GSList *tmp_list;
-
-  if (selection == GDK_NONE)
-    selection = GDK_SELECTION_CLIPBOARD;
-
-  clipboards = g_object_get_data (G_OBJECT (display), "gtk-clipboard-list");
-
-  tmp_list = clipboards;
-  while (tmp_list)
-    {
-      clipboard = tmp_list->data;
-      if (clipboard->selection == selection)
-        break;
-
-      tmp_list = tmp_list->next;
-    }
-
-  if (!tmp_list && !only_if_exists)
-    {
-      clipboard = g_object_new (GTK_TYPE_CLIPBOARD, NULL);
-      clipboard->selection = selection;
-      clipboard->display = display;
-
-      clipboards = g_slist_prepend (clipboards, clipboard);
-      g_object_set_data (G_OBJECT (display), I_("gtk-clipboard-list"), clipboards);
-      g_signal_connect (display, "closed",
-                        G_CALLBACK (clipboard_display_closed), clipboard);
-      gdk_display_request_selection_notification (display, selection);
-    }
-  
-  return clipboard;
-}
-
-GtkClipboard *
-gtk_clipboard_get_for_display (GdkDisplay *display,
-                               GdkAtom     selection)
-{
-  g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
-  g_return_val_if_fail (!gdk_display_is_closed (display), NULL);
-
-  return clipboard_peek (display, selection, FALSE);
-}
-
-GtkClipboard *
-gtk_clipboard_get (GdkAtom selection)
-{
-  return gtk_clipboard_get_for_display (gdk_display_get_default (), selection);
-}
-
-
 struct _SetContentClosure {
     GtkClipboard *clipboard;
     GtkClipboardGetFunc get_func;
@@ -244,7 +120,8 @@ static void
 clipboard_owner_destroyed (gpointer data,
                           GObject *owner)
 {
-  GtkClipboard *clipboard = (GtkClipboard *) data;
+  GtkClipboardWayland *clipboard = GTK_CLIPBOARD_WAYLAND (data);
+  GtkClipboard *gtkclipboard = GTK_CLIPBOARD (data);
   SetContentClosure *last_closure = clipboard->last_closure;
 
   last_closure->userdata = NULL;
@@ -252,18 +129,19 @@ clipboard_owner_destroyed (gpointer data,
   last_closure->clear_func = NULL;
   last_closure->have_owner = FALSE;
 
-  gtk_clipboard_clear (clipboard);
+  gtk_clipboard_clear (gtkclipboard);
 }
 
 static gboolean
-gtk_clipboard_set_contents (GtkClipboard         *clipboard,
-                            const GtkTargetEntry *targets,
-                            guint                 n_targets,
-                            GtkClipboardGetFunc   get_func,
-                            GtkClipboardClearFunc clear_func,
-                            gpointer              user_data,
-                            gboolean              have_owner)
-{
+gtk_clipboard_wayland_set_contents (GtkClipboard         *gtkclipboard,
+                                    const GtkTargetEntry *targets,
+                                    guint                 n_targets,
+                                    GtkClipboardGetFunc   get_func,
+                                    GtkClipboardClearFunc clear_func,
+                                    gpointer              user_data,
+                                    gboolean              have_owner)
+{
+  GtkClipboardWayland *clipboard = GTK_CLIPBOARD_WAYLAND (gtkclipboard);
   GdkDeviceManager *device_manager;
   GdkDevice *device;
   gint i;
@@ -274,10 +152,10 @@ gtk_clipboard_set_contents (GtkClipboard         *clipboard,
   if (!last_closure ||
       (!last_closure->have_owner && have_owner) ||
       (last_closure->userdata != user_data)) {
-    gtk_clipboard_clear (clipboard);
+    gtk_clipboard_clear (gtkclipboard);
 
     closure = g_new0 (SetContentClosure, 1);
-    closure->clipboard = clipboard;
+    closure->clipboard = gtkclipboard;
     closure->userdata = user_data;
     closure->have_owner = have_owner;
 
@@ -317,55 +195,10 @@ gtk_clipboard_set_contents (GtkClipboard         *clipboard,
   return TRUE;
 }
 
-gboolean
-gtk_clipboard_set_with_data (GtkClipboard          *clipboard,
-                             const GtkTargetEntry  *targets,
-                             guint                  n_targets,
-                             GtkClipboardGetFunc    get_func,
-                             GtkClipboardClearFunc  clear_func,
-                             gpointer               user_data)
-{
-  g_return_val_if_fail (clipboard != NULL, FALSE);
-  g_return_val_if_fail (targets != NULL, FALSE);
-  g_return_val_if_fail (get_func != NULL, FALSE);
-
-  return gtk_clipboard_set_contents (clipboard, targets, n_targets,
-                                     get_func, clear_func, user_data,
-                                     FALSE);
-}
-
-gboolean
-gtk_clipboard_set_with_owner (GtkClipboard          *clipboard,
-                              const GtkTargetEntry  *targets,
-                              guint                  n_targets,
-                              GtkClipboardGetFunc    get_func,
-                              GtkClipboardClearFunc  clear_func,
-                              GObject               *owner)
-{
-  g_return_val_if_fail (clipboard != NULL, FALSE);
-  g_return_val_if_fail (targets != NULL, FALSE);
-  g_return_val_if_fail (get_func != NULL, FALSE);
-  g_return_val_if_fail (G_IS_OBJECT (owner), FALSE);
-
-  return gtk_clipboard_set_contents (clipboard, targets, n_targets,
-                                     get_func, clear_func, owner,
-                                     TRUE);
-}
-
-GObject *
-gtk_clipboard_get_owner (GtkClipboard *clipboard)
-{
-  g_return_val_if_fail (clipboard != NULL, NULL);
-
-  if (clipboard->owner)
-    return clipboard->owner;
-  else
-    return NULL;
-}
-
-void
-gtk_clipboard_clear (GtkClipboard *clipboard)
+static void
+gtk_clipboard_wayland_clear (GtkClipboard *gtkclipboard)
 {
+  GtkClipboardWayland *clipboard = GTK_CLIPBOARD_WAYLAND (gtkclipboard);
   GdkDeviceManager *device_manager;
   GdkDevice *device;
 
@@ -379,7 +212,7 @@ gtk_clipboard_clear (GtkClipboard *clipboard)
 
   if (clipboard->last_closure->clear_func)
     {
-      clipboard->last_closure->clear_func (clipboard,
+      clipboard->last_closure->clear_func (gtkclipboard,
                                            clipboard->last_closure->userdata);
     }
 
@@ -392,94 +225,6 @@ gtk_clipboard_clear (GtkClipboard *clipboard)
   clipboard->last_closure = NULL;
 }
 
-static void 
-text_get_func (GtkClipboard     *clipboard,
-               GtkSelectionData *selection_data,
-               guint             info,
-               gpointer          data)
-{
-  gtk_selection_data_set_text (selection_data, data, -1);
-}
-
-static void 
-text_clear_func (GtkClipboard *clipboard,
-                 gpointer      data)
-{
-  g_free (data);
-}
-
-void
-gtk_clipboard_set_text (GtkClipboard *clipboard,
-                        const gchar  *text,
-                        gint          len)
-{
-  GtkTargetEntry target = { "text/plain;charset=utf-8", 0, 0 };
-
-  g_return_if_fail (clipboard != NULL);
-  g_return_if_fail (text != NULL);
-
-  if (len < 0)
-    len = strlen (text);
-
-  gtk_clipboard_set_with_data (clipboard, 
-                               &target, 1,
-                               text_get_func, text_clear_func,
-                               g_strndup (text, len));
-  gtk_clipboard_set_can_store (clipboard, NULL, 0);
-}
-
-
-static void
-pixbuf_get_func (GtkClipboard     *clipboard,
-                 GtkSelectionData *selection_data,
-                 guint             info,
-                 gpointer          data)
-{
-  gtk_selection_data_set_pixbuf (selection_data, data);
-}
-
-static void 
-pixbuf_clear_func (GtkClipboard *clipboard,
-                   gpointer      data)
-{
-  g_object_unref (data);
-}
-
-void
-gtk_clipboard_set_image (GtkClipboard *clipboard,
-                         GdkPixbuf    *pixbuf)
-{
-  GtkTargetList *list;
-  GList *l;
-  GtkTargetEntry *targets;
-  gint n_targets, i;
-
-  g_return_if_fail (clipboard != NULL);
-  g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
-
-  list = gtk_target_list_new (NULL, 0);
-  gtk_target_list_add_image_targets (list, 0, TRUE);
-
-  n_targets = g_list_length (list->list);
-  targets = g_new0 (GtkTargetEntry, n_targets);
-  for (l = list->list, i = 0; l; l = l->next, i++)
-    {
-      GtkTargetPair *pair = (GtkTargetPair *)l->data;
-      targets[i].target = gdk_atom_name (pair->target);
-    }
-
-  gtk_clipboard_set_with_data (clipboard, 
-                               targets, n_targets,
-                               pixbuf_get_func, pixbuf_clear_func,
-                               g_object_ref (pixbuf));
-  gtk_clipboard_set_can_store (clipboard, NULL, 0);
-
-  for (i = 0; i < n_targets; i++)
-    g_free (targets[i].target);
-  g_free (targets);
-  gtk_target_list_unref (list);
-}
-
 typedef struct {
     GtkClipboard *clipboard;
     GCallback cb;
@@ -507,11 +252,11 @@ _request_generic_cb (GdkDevice   *device,
   g_free (closure);
 }
 
-void
-gtk_clipboard_request_contents (GtkClipboard            *clipboard,
-                                GdkAtom                  target,
-                                GtkClipboardReceivedFunc callback,
-                                gpointer                 user_data)
+static void
+gtk_clipboard_wayland_request_contents (GtkClipboard            *gtkclipboard,
+                                        GdkAtom                  target,
+                                        GtkClipboardReceivedFunc callback,
+                                        gpointer                 user_data)
 {
   GdkDeviceManager *device_manager;
   GdkDevice *device;
@@ -521,7 +266,7 @@ gtk_clipboard_request_contents (GtkClipboard            *clipboard,
   device = gdk_device_manager_get_client_pointer (device_manager);
 
   closure = g_new0 (ClipboardRequestClosure, 1);
-  closure->clipboard = clipboard;
+  closure->clipboard = gtkclipboard;
   closure->cb = (GCallback)callback;
   closure->userdata = user_data;
   closure->target = target;
@@ -534,412 +279,24 @@ gtk_clipboard_request_contents (GtkClipboard            *clipboard,
 }
 
 static void
-_request_text_cb (GdkDevice   *device,
-                  const gchar *data,
-                  gsize        len,
-                  gpointer     userdata)
+gtk_clipboard_wayland_owner_change (GtkClipboard        *clipboard,
+                                    GdkEventOwnerChange *event)
 {
-  ClipboardRequestClosure *closure = (ClipboardRequestClosure *)userdata;
-  GtkClipboardTextReceivedFunc cb = (GtkClipboardTextReceivedFunc)closure->cb;
 
-  cb (closure->clipboard, data, closure->userdata);
-
-  g_free (closure);
 }
 
-void
-gtk_clipboard_request_text (GtkClipboard                *clipboard,
-                            GtkClipboardTextReceivedFunc callback,
-                            gpointer                     user_data)
-{
-  GdkDeviceManager *device_manager;
-  GdkDevice *device;
-
-  ClipboardRequestClosure *closure;
-
-  device_manager = gdk_display_get_device_manager (gdk_display_get_default ());
-  device = gdk_device_manager_get_client_pointer (device_manager);
-
-  closure = g_new0 (ClipboardRequestClosure, 1);
-  closure->clipboard = clipboard;
-  closure->cb = (GCallback)callback;
-  closure->userdata = user_data;
-  gdk_wayland_device_request_selection_content (device,
-                                                "text/plain;charset=utf-8",
-                                                _request_text_cb,
-                                                closure);
-}
-
-void
-gtk_clipboard_request_rich_text (GtkClipboard                    *clipboard,
-                                 GtkTextBuffer                   *buffer,
-                                 GtkClipboardRichTextReceivedFunc callback,
-                                 gpointer                         user_data)
-{
-  /* FIXME: Implement */
-}
-
-void
-gtk_clipboard_request_image (GtkClipboard                  *clipboard,
-                             GtkClipboardImageReceivedFunc  callback,
-                             gpointer                       user_data)
-{
-  /* FIXME: Implement */
-}
-
-void
-gtk_clipboard_request_uris (GtkClipboard                *clipboard,
-                            GtkClipboardURIReceivedFunc  callback,
-                            gpointer                     user_data)
-{
-  /* FIXME: Implement */
-}
-
-void
-gtk_clipboard_request_targets (GtkClipboard                    *clipboard,
-                               GtkClipboardTargetsReceivedFunc  callback,
-                               gpointer                         user_data)
-{
-  GdkAtom *targets;
-  gint n_targets;
-
-  gtk_clipboard_wait_for_targets (clipboard, &targets, &n_targets);
-
-  callback (clipboard, targets, n_targets, user_data);
-
-  g_free (targets);
-}
-
-typedef struct {
-    GMainLoop *loop;
-    GtkSelectionData *selection_data;
-} WaitClosure;
-
 static void
-_wait_for_contents_cb (GtkClipboard     *clipboard,
-                       GtkSelectionData *selection_data,
-                       gpointer          userdata)
-{
-  WaitClosure *closure = (WaitClosure *)userdata;
-
-  if (gtk_selection_data_get_length (selection_data) != -1)
-    closure->selection_data = gtk_selection_data_copy (selection_data);
-
-  g_main_loop_quit (closure->loop);
-}
-
-GtkSelectionData *
-gtk_clipboard_wait_for_contents (GtkClipboard *clipboard,
-                                 GdkAtom       target)
-{
-  GdkDeviceManager *device_manager;
-  GdkDevice *device;
-  WaitClosure *closure;
-  GtkSelectionData *selection_data = NULL;
-
-  g_return_val_if_fail (clipboard != NULL, NULL);
-  g_return_val_if_fail (target != GDK_NONE, NULL);
-
-  device_manager = gdk_display_get_device_manager (clipboard->display);
-  device = gdk_device_manager_get_client_pointer (device_manager);
-
-  if (target == gdk_atom_intern_static_string ("TARGETS")) 
-    {
-      GdkAtom *atoms;
-      gint nr_atoms;
-
-      selection_data = g_slice_new0 (GtkSelectionData);
-      selection_data->selection = GDK_SELECTION_CLIPBOARD;
-      selection_data->target = target;
-
-      nr_atoms = gdk_wayland_device_get_selection_type_atoms (device, &atoms);
-      gtk_selection_data_set (selection_data,
-                              GDK_SELECTION_TYPE_ATOM, 32,
-                              (guchar *)atoms,
-                              32 * nr_atoms);
-
-      g_free (atoms);
-
-      return selection_data;
-    }
-
-  closure = g_new0 (WaitClosure, 1);
-  closure->selection_data = NULL;
-  closure->loop = g_main_loop_new (NULL, TRUE);
-
-  gtk_clipboard_request_contents (clipboard,
-                                  target,
-                                  _wait_for_contents_cb,
-                                  closure);
-
-  if (g_main_loop_is_running (closure->loop))
-    {
-      gdk_threads_leave ();
-      g_main_loop_run (closure->loop);
-      gdk_threads_enter ();
-    }
-
-  g_main_loop_unref (closure->loop);
-
-  selection_data = closure->selection_data;
-
-  g_free (closure);
-
-  return selection_data;
-}
-
-gchar *
-gtk_clipboard_wait_for_text (GtkClipboard *clipboard)
-{
-  GtkSelectionData *data;
-  gchar *result;
-
-  data =
-    gtk_clipboard_wait_for_contents (clipboard,
-                                     gdk_atom_intern_static_string ("text/plain;charset=utf-8"));
-
-  result = (gchar *)gtk_selection_data_get_text (data);
-
-  gtk_selection_data_free (data);
-
-  return result;
-}
-
-GdkPixbuf *
-gtk_clipboard_wait_for_image (GtkClipboard *clipboard)
-{
-  const gchar *priority[] = { "image/png",
-      "image/tiff",
-      "image/jpeg",
-      "image/gif",
-      "image/bmp" };
-  int i;
-  GtkSelectionData *data;
-
-  for (i = 0; i < G_N_ELEMENTS (priority); i++) 
-    {
-      data = gtk_clipboard_wait_for_contents (clipboard, gdk_atom_intern_static_string (priority[i]));
-
-      if (data)
-        {
-          GdkPixbuf *pixbuf = gtk_selection_data_get_pixbuf (data);
-
-          gtk_selection_data_free (data);
-
-          return pixbuf;
-        }
-    }
-
-  return NULL;
-}
-
-guint8 *
-gtk_clipboard_wait_for_rich_text (GtkClipboard  *clipboard,
-                                  GtkTextBuffer *buffer,
-                                  GdkAtom       *format,
-                                  gsize         *length)
+gtk_clipboard_wayland_set_can_store (GtkClipboard         *clipboard,
+                                     const GtkTargetEntry *targets,
+                                     gint                  n_targets)
 {
   /* FIXME: Implement */
-  return NULL;
-}
-
-gchar **
-gtk_clipboard_wait_for_uris (GtkClipboard *clipboard)
-{
-  GtkSelectionData *data;
-
-  data =
-    gtk_clipboard_wait_for_contents (clipboard,
-                                     gdk_atom_intern_static_string ("text/uri-list"));
-  if (data)
-    {
-      gchar **uris;
-
-      uris = gtk_selection_data_get_uris (data);
-      gtk_selection_data_free (data);
-
-      return uris;
-    }  
-
-  return NULL;
-}
-
-GdkDisplay *
-gtk_clipboard_get_display (GtkClipboard *clipboard)
-{
-  g_return_val_if_fail (clipboard != NULL, NULL);
-
-  return clipboard->display;
-}
-
-gboolean
-gtk_clipboard_wait_is_text_available (GtkClipboard *clipboard)
-{
-  GtkSelectionData *data;
-  gboolean result = FALSE;
-
-  data =
-    gtk_clipboard_wait_for_contents (clipboard,
-                                     gdk_atom_intern_static_string ("TARGETS"));
-  if (data)
-    {
-      result = gtk_selection_data_targets_include_text (data);
-      gtk_selection_data_free (data);
-    }
-
-  return result;
-}
-
-gboolean
-gtk_clipboard_wait_is_rich_text_available (GtkClipboard  *clipboard,
-                                           GtkTextBuffer *buffer)
-{
-  GtkSelectionData *data;
-  gboolean result = FALSE;
-
-  g_return_val_if_fail (GTK_IS_CLIPBOARD (clipboard), FALSE);
-  g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
-
-  data =
-    gtk_clipboard_wait_for_contents (clipboard,
-                                     gdk_atom_intern_static_string ("TARGETS"));
-  if (data)
-    {
-      result = gtk_selection_data_targets_include_rich_text (data, buffer);
-      gtk_selection_data_free (data);
-    }
-
-  return result;
-}
-
-gboolean
-gtk_clipboard_wait_is_image_available (GtkClipboard *clipboard)
-{
-  GtkSelectionData *data;
-  gboolean result = FALSE;
-
-  data =
-    gtk_clipboard_wait_for_contents (clipboard, 
-                                     gdk_atom_intern_static_string ("TARGETS"));
-  if (data)
-    {
-      result = gtk_selection_data_targets_include_image (data, FALSE);
-      gtk_selection_data_free (data);
-    }
-
-  return result;
-}
-
-gboolean
-gtk_clipboard_wait_is_uris_available (GtkClipboard *clipboard)
-{
-  GtkSelectionData *data;
-  gboolean result = FALSE;
-
-  data =
-    gtk_clipboard_wait_for_contents (clipboard, 
-                                     gdk_atom_intern_static_string ("TARGETS"));
-  if (data)
-    {
-      result = gtk_selection_data_targets_include_uri (data);
-      gtk_selection_data_free (data);
-    }
-
-  return result;
-}
-
-gboolean
-gtk_clipboard_wait_for_targets (GtkClipboard  *clipboard,
-                                GdkAtom      **targets,
-                                gint          *n_targets)
-{
-  GtkSelectionData *data;
-  gboolean result = FALSE;
-
-  g_return_val_if_fail (clipboard != NULL, FALSE);
-
-  data =
-    gtk_clipboard_wait_for_contents (clipboard,
-                                     gdk_atom_intern_static_string ("TARGETS"));
-
-  if (data)
-    {
-      GdkAtom *tmp_targets;
-      gint tmp_n_targets;
-
-      result = gtk_selection_data_get_targets (data,
-                                               &tmp_targets,
-                                               &tmp_n_targets);
-
-      if (n_targets)
-        *n_targets = tmp_n_targets;
-
-      if (targets)
-        *targets = tmp_targets;
-      else
-        g_free (tmp_targets);
-
-      gtk_selection_data_free (data);
-    }
-
-  return result;
 }
 
 static void
-gtk_clipboard_owner_change (GtkClipboard        *clipboard,
-                            GdkEventOwnerChange *event)
-{
-
-}
-
-gboolean
-gtk_clipboard_wait_is_target_available (GtkClipboard *clipboard,
-                                        GdkAtom       target)
-{
-  GdkAtom *targets;
-  gint i, n_targets;
-  gboolean retval = FALSE;
-
-  g_return_val_if_fail (clipboard != NULL, FALSE);
-
-  if (!gtk_clipboard_wait_for_targets (clipboard, &targets, &n_targets))
-    return FALSE;
-
-  for (i = 0; i < n_targets; i++)
-    {
-      if (targets[i] == target)
-        {
-          retval = TRUE;
-          break;
-        }
-    }
-
-  g_free (targets);
-
-  return retval;
-}
-
-void
-_gtk_clipboard_handle_event (GdkEventOwnerChange *event)
-{
-}
-
-void
-gtk_clipboard_set_can_store (GtkClipboard         *clipboard,
-                             const GtkTargetEntry *targets,
-                             gint                  n_targets)
-{
-  /* FIXME: Implement */
-}
-
-void
-gtk_clipboard_store (GtkClipboard *clipboard)
+gtk_clipboard_wayland_store (GtkClipboard *clipboard)
 {
   /* FIXME: Implement */
 }
 
-void
-_gtk_clipboard_store_all (void)
-{
-  /* FIXME: Implement */
-}
+#endif /* GDK_WINDOWING_WAYLAND */
diff --git a/gtk/gtkclipboard-waylandprivate.h b/gtk/gtkclipboard-waylandprivate.h
new file mode 100644 (file)
index 0000000..7a5b58e
--- /dev/null
@@ -0,0 +1,54 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2000 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GTK_CLIPBOARD_WAYLAND_WAYLAND_PRIVATE_H__
+#define __GTK_CLIPBOARD_WAYLAND_WAYLAND_PRIVATE_H__
+
+#include <gdk/wayland/gdkwayland.h>
+#include <gtk/gtkclipboardprivate.h>
+
+#ifdef GDK_WINDOWING_WAYLAND
+
+#define GTK_TYPE_CLIPBOARD_WAYLAND            (gtk_clipboard_wayland_get_type ())
+#define GTK_CLIPBOARD_WAYLAND(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CLIPBOARD_WAYLAND, GtkClipboardWayland))
+#define GTK_IS_CLIPBOARD_WAYLAND(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CLIPBOARD_WAYLAND))
+#define GTK_CLIPBOARD_WAYLAND_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CLIPBOARD_WAYLAND, GtkClipboardWaylandClass))
+#define GTK_IS_CLIPBOARD_WAYLAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CLIPBOARD_WAYLAND))
+#define GTK_CLIPBOARD_WAYLAND_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CLIPBOARD_WAYLAND, GtkClipboardWaylandClass))
+
+typedef struct _GtkClipboardWayland GtkClipboardWayland;
+typedef struct _GtkClipboardWaylandClass GtkClipboardWaylandClass;
+
+typedef struct _SetContentClosure SetContentClosure;
+
+struct _GtkClipboardWayland
+{
+  GtkClipboard parent_instance;
+
+  SetContentClosure *last_closure;
+};
+
+struct _GtkClipboardWaylandClass
+{
+  GtkClipboardClass parent_class;
+};
+
+GType         gtk_clipboard_wayland_get_type (void) G_GNUC_CONST;
+
+#endif /* GDK_WINDOWING_WAYLAND */
+
+#endif /* __GTK_CLIPBOARD_WAYLAND_WAYLAND_PRIVATE_H__ */
index 24073523cfa643977900f1c9e7c49f30cabf1cfb..a460e477bda221181c7630427135d24525f8e5e9 100644 (file)
@@ -23,6 +23,9 @@
 
 #include "gtkclipboard.h"
 #include "gtkclipboardprivate.h"
+#ifdef GDK_WINDOWING_WAYLAND
+#include "gtkclipboard-waylandprivate.h"
+#endif
 #include "gtkinvisible.h"
 #include "gtkmain.h"
 #include "gtkmarshalers.h"
@@ -1914,7 +1917,13 @@ clipboard_peek (GdkDisplay *display,
 
   if (!tmp_list && !only_if_exists)
     {
-      clipboard = g_object_new (GTK_TYPE_CLIPBOARD, NULL);
+#ifdef GDK_WINDOWING_WAYLAND
+      if (GDK_IS_WAYLAND_DISPLAY (display))
+        clipboard = g_object_new (GTK_TYPE_CLIPBOARD_WAYLAND, NULL);
+      else
+#endif
+        clipboard = g_object_new (GTK_TYPE_CLIPBOARD, NULL);
+
       clipboard->selection = selection;
       clipboard->display = display;
       clipboard->n_cached_targets = -1;